import {Component, Input, OnInit} from "@angular/core";
import {ViewCell} from "ng2-smart-table";
import {NbDateService} from "@nebular/theme";

@Component({
  template: `
    {{renderValue}}
  `,
})
export class CustomDateRender implements ViewCell, OnInit {

  renderValue: string;

  @Input() value: string | number;
  @Input() rowData: any;

  constructor(private dateService:NbDateService<Date>){}

  ngOnInit() {
    if (typeof this.value === "string") {
      try {
        const date = this.dateService.parse(this.value, "yyyy-MM-ddTHH:mm:ss.SSS");
        this.renderValue = this.dateService.format(date, 'yyyy-MM-dd');
      }catch (e) {
        this.renderValue="#";
      }
    }else {
      this.renderValue = '#';
    }
  }
}
